package mgslangpack;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
public class DeleteBooking
{
    public DeleteBooking() throws Exception
    {
        final TextField tf1;
        Label l1,l9;
        Button b1,b2,b3;
        final JFrame jf;
        jf= new JFrame("Delete Booking");
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setSize(800,600);
        jf.setLayout(null);
        jf.setVisible(false);
        Container ctn=jf.getContentPane();
        ctn.setBackground(Color.LIGHT_GRAY);
        JLabel Pic;
        Pic=new JLabel(new ImageIcon("Titanium-Wedding_Rings.jpg"));
        Pic.setBounds(250,500,220,220);
        ctn.add(Pic);
        Font f1 = new Font("Lucida Handwriting",Font.BOLD,24);
        l9 = new Label("Select Booking Reff. of booking to delete from table below:");
        l9.setBounds(20,10,720,40);
        l9.setFont(f1);
        jf.add(l9);
        l1= new Label("Refference No:");
        l1.setBounds(70,250,200,30);
        l1.setFont(f1);
        jf.add(l1);
        tf1 = new TextField();tf1.setBounds(310,250,100,30);jf.add(tf1);
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        final Connection con =
        DriverManager.getConnection("jdbc:odbc:TheOZ_DB","","");
        final TextArea ta = new TextArea();
        ta.setBounds(450,100,300,400);
        ta.setEditable(false);
        ta.setBackground(Color.WHITE);
        jf.add(ta);
        String bd,nb,rn;
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery("Select * From Bookings");
        while(rs.next())
        {
            bd = rs.getString(1);
            nb = rs.getString(2);
            rn = rs.getString(3);

            ta.append("\nBooking Date:\t"+bd+"\nNumber of guest:\t"+nb+"\nRefference no:\t"+rn+"\n\n");
            ta.append(" ");
        }
        b1 = new Button("Delete");
        b1.setBounds(70,315,80,30);
        b1.addActionListener( new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                try
                {
                    String s1;
                    s1 = tf1.getText();
                    PreparedStatement ps = con.prepareStatement("DELETE FROM Bookings WHERE BkReff='"+s1+"'");
                    int i = ps.executeUpdate();
                    JOptionPane.showMessageDialog(null,"Booking details deleted from database.");
                    tf1.setText("");
                }
		catch(Exception e1){JOptionPane.showMessageDialog(null,"Error!");}
            }
        }
        );
        jf.add(b1);
        b2 = new Button("Back");
        b2.setBounds(80,520,80,30);
        b2.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e2)
            {
                try
                {
                    jf.hide();
                    new MenuStaff();
                }
                catch(Exception e3){}
            }
        }
        );
        jf.add(b2);
        jf.add(b2);
        b3 = new Button("Exit");
        b3.setBounds(600,520,80,30);
        b3.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e2)
            {
                try
                {
                    System.exit(0);
                }
                catch(Exception e3){}
            }
        }
        );
        jf.add(b3);
        jf.show();
    }
}
/******************************************************************************/